<?php
/**
 * Creater : cuongnh
 * Date : 20/07/2011
 * Idea : Class Xu ly thong tin chuyen muc
 */
class web_homeController extends  Zend_Controller_Action {	
	//Bien public luu quyen
	public $_publicPermission;
	public function init(){
		//Load cau hinh thu muc trong file config.ini
        $tempDirApp = Zend_Registry::get('conDirApp');
		$this->_dirApp = $tempDirApp->toArray();
		$this->view->dirApp = $tempDirApp->toArray();
		//Cau hinh cho Zend_layout
		Zend_Layout::startMvc(array(
			    'layoutPath' => $this->_dirApp['layout'],
			    'layout' => 'index'			    
			    ));	
		//Load ca thanh phan cau vao trang layout (index.phtml)
		$response = $this->getResponse();
		//Load cau hinh thu muc trong file config.ini de lay ca hang so dung chung
        $tempConstPublic = Zend_Registry::get('ConstPublic');
		$this->_ConstPublic = $tempConstPublic->toArray();
				
		//Lay duong dan thu muc goc (path directory root)
		$this->view->baseUrl = $this->_request->getBaseUrl() . "/public/";	
		
		//Goi lop Listxml_modList
		Zend_Loader::loadClass('web_modWebMenu');
		//Lay tat ca cac chuyen muc
		$objWebMenu = new web_modWebMenu();
		$arrResul = $objWebMenu->WebMenuGetAll('4',$_SESSION['OWNER_CODE'],'3','1');
		$this->view->arrMenu = $arrResul;	
		//Lay nhac viec cho cong viec
		/*
		$arrTaskNoty = $objWebMenu->TaskWorkNotyGetAll($_SESSION['staff_id']);
		if($arrTaskNoty[0]['SENT'] > 0){
			$this->view->TaskSent = '<span style="color:#FF0000;"> ('.$arrTaskNoty[0]['SENT'].')</span>';	
		}else{
			$this->view->TaskSent = '';	
		}
		if($arrTaskNoty[0]['REC'] > 0){
			$this->view->TaskRec = '<span style="color:#FF0000;"> ('.$arrTaskNoty[0]['REC'].')</span>';	
		}else{
			$this->view->TaskRec = '';	
		}*/
		//var_dump($arrTaskNoty);
		$sliidvisit = $this->_request->getParam('sliid','');
		$sleftmenu = $this->_request->getParam('sleftmenu','');	
		$srightmenu = $this->_request->getParam('srightmenu','');	
		//Neu khong co gia tri thì lay trong cookie
		if ($sleftmenu <> ""){
			$this->view->sleftmenu = $sleftmenu;	
			$this->view->srightmenu = '';
			Efy_Library::_createCookie("leftvisit",$sleftmenu);
			Efy_Library::_createCookie("rightvisit",'');	
		}else{
			if ($srightmenu <> ""){
				$this->view->srightmenu = $srightmenu;	
				$this->view->sleftmenu = '';		
				Efy_Library::_createCookie("leftvisit",'');
				Efy_Library::_createCookie("rightvisit",$srightmenu);
			}else{
				$sleftmenu = Efy_Library::_getCookie("leftvisit");
				if ($sleftmenu <> ""){
					$this->view->sleftmenu = $sleftmenu;	
					$this->view->srightmenu = '';
				}else{
					$srightmenu = Efy_Library::_getCookie("rightvisit");
					$this->view->sleftmenu = '';	
					$this->view->srightmenu = $srightmenu;
				}
			}
		}
		if ($sliidvisit == "" || is_null($sliidvisit) || !isset($sliidvisit)){
			$sliidvisit = Efy_Library::_getCookie("headervisit");
		}else{
			Efy_Library::_createCookie("headervisit",$sliidvisit);
		}
		$this->view->sliidvisit = $sliidvisit;	
		$this->view->sleftmenu = $sleftmenu;	
		$this->view->srightmenu = $srightmenu;	
		//echo $sliidvisit;
		//Lay cac hang so su dung trong JS public
		Zend_Loader::loadClass('Efy_Init_Config');	
		$ojbEfyInitConfig = new Efy_Init_Config();
		$this->view->UrlAjax = $ojbEfyInitConfig->_setUrlAjax();	
		$this->view->arrConst =	$ojbEfyInitConfig->_setProjectPublicConst();
		$this->view->JSPublicConst = $ojbEfyInitConfig->_setJavaScriptPublicVariable();	
		//So luong tin bai trong mot chuyen muc
		$this->view->CountInMenu = $ojbEfyInitConfig->_setCountInMenu();	
		//Ky tu dac biet phan tach giua cac phan tu
		$this->view->delimitor 			= $this->_ConstPublic['delimitor'];
		//Tao doi tuong XML
		Zend_Loader::loadClass('Efy_Publib_Xml');		
		
		// Load tat ca cac file Js va Css
		//$this->view->LoadAllFileJsCss = Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','jsWeb.js,util.js,js_calendar.js',',','js') . Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','ajax.js',',','js') . Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','jquery-1.4.2.min.js,jQuery.equalHeights.js',',','js'). Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js/LibSearch','actb_search.js,common_search.js',',','js');										
		$JSandStyle = Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','jsWeb.js,util.js,js_calendar.js',',','js') . Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','ajax.js',',','js') . Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','jquery-1.4.2.min.js,jQuery.equalHeights.js',',','js'). Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js/LibSearch','actb_search.js,common_search.js',',','js');												
		$JSandStyle.= Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','ui/i18n/jquery.ui.datepicker-vi.js',',','js');
		$JSandStyle.= Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-js','ui/jquery-ui-1.8.14.custom.min.js',',','js');
		$JSandStyle.= Efy_Publib_Library::_getAllFileJavaScriptCss('','efy-style','simpleModal.css,themes/humanity/jquery-ui-1.8.13.custom.css,themes/base/calendar.css',',','css');
		$this->view->LoadAllFileJsCss = $JSandStyle;										
		/* Ket thuc*/
		//Dinh nghia current modul code
		$this->view->currentModulCode = "WEB_HOME";
		$this->view->currentModulCodeForLeft = "WEB_HOME";		
		
		//Lay tra tri trong Cookie set an hien menu
		$sGetLeftValueInCookie = Efy_Library::_getCookie("showHideLeftMenu");
		$sGetRightValueInCookie = Efy_Library::_getCookie("showHideRightMenu");
		//Neu chua ton tai thi khoi tao
		if ($sGetLeftValueInCookie == "" || is_null($sGetLeftValueInCookie) || !isset($sGetLeftValueInCookie)){
			Efy_Library::_createCookie("showHideLeftMenu",1);
			Efy_Library::_createCookie("LeftImageUrlPath",$this->_request->getBaseUrl() . "/public/images/close_left_menu.gif");
			//Mac dinh hien thi menu trai
			$this->view->hideDisplayMeneLeft = 1;// = 1 : hien thi menu
			//Hien thi anh dong menu trai
			$this->view->ShowHideLeftimageUrlPath = $this->_request->getBaseUrl() . "/public/images/close_left_menu.gif";
		}else{
			if ($sGetLeftValueInCookie != 0){
				$this->view->hideDisplayMeneLeft = 1;// = 1 : hien thi menu
			}else{
				$this->view->hideDisplayMeneLeft = "";// = "" : an menu
			}
			//Lay dia chi anh trong Cookie
			$this->view->ShowHideLeftimageUrlPath = Efy_Library::_getCookie("LeftImageUrlPath");
		}
		//ben phai
		if ($sGetRightValueInCookie == "" || is_null($sGetRightValueInCookie) || !isset($sGetRightValueInCookie)){
			Efy_Library::_createCookie("showHideRightMenu",1);
			Efy_Library::_createCookie("RightImageUrlPath",$this->_request->getBaseUrl() . "/public/images/open_left_menu.gif");
			//Mac dinh hien thi menu trai
			$this->view->hideDisplayMeneRight = 1;// = 1 : hien thi menu
			//Hien thi anh dong menu trai
			$this->view->ShowHideRightimageUrlPath = $this->_request->getBaseUrl() . "/public/images/open_left_menu.gif";
		}else{
			if ($sGetRightValueInCookie != 0){
				$this->view->hideDisplayMeneRight = 1;// = 1 : hien thi menu
			}else{
				$this->view->hideDisplayMeneRight = "";// = "" : an menu
			}
			//Lay dia chi anh trong Cookie
			$this->view->ShowHideRightimageUrlPath = Efy_Library::_getCookie("RightImageUrlPath");
		}
		$sActionName = $this->_request->getActionName();
		if ($sActionName == 'edittraffic' || $sActionName == 'traffic'|| $sActionName == 'addtraffic'){
			$this->view->hideDisplayMeneRight = "";
		}
		//Lay gia tri tim kiem
		$sSearch = $this->_request->getParam('FullTextSearch','');
		$this->view->sSearch = $sSearch;	
		//Hien thi file template
		$response->insert('header', $this->view->renderLayout('header.phtml','./application/views/scripts/'));    	//Hien thi header 
		$response->insert('left', $this->view->renderLayout('left_home.phtml','./application/views/scripts/'));    		//Hien thi header 	
		$response->insert('right', $this->view->renderLayout('right_home.phtml','./application/views/scripts/'));    		//Hien thi header 	    
        $response->insert('footer', $this->view->renderLayout('footer.phtml','./application/views/scripts/'));  	//Hien thi footer
 	}
		
	/**
	 * Idea: Thuc hien phuong thuc Action hien thi danh sach doi tuong
	 */
	public function indexAction(){	
		//Lay URL 
		$sUrl = $_SERVER['REQUEST_URI'];
		$this->view->sUrl = $sUrl;		
		// Tieu de lich cong tac
		$this->view->sheTitle = "LỊCH CÔNG TÁC UBND TRONG NGÀY";
		// Tieu de CONG VIEC
		$this->view->worTitle = "CÔNG VIỆC CÁ NHÂN";
		// Tao doi tuong Zend_Filter
		$objFilter = new Zend_Filter();
		$ojbEfyLib = new Efy_Library();
		$objDocFun = new Efy_Function_DocFunctions();
		$objWebMenu = new web_modWebMenu();
		//Lay thong tin lich ca nhan trong ngay
		$v_year = date('Y');					
		$v_week = date("W");
		$v_day = date("D");	
		$v_month = date("m");
		if(($v_month=='12')&&($v_week=='01')){
			$v_year = $v_year + 1;
		}
		$sOwner_name = $_SESSION['OWNER_CODE'];	
		$arrScheduleStaff = $objWebMenu->Schedule_StaffGetSingle($_SESSION['staff_id'],$v_week,$v_year);
		//var_dump($arrScheduleStaff);		
		if ($iNumRowOnPage <= $this->view->NumberRowOnPage){
			$iNumRowOnPage = $this->view->NumberRowOnPage;
		}
		//$this->view->arrScheduleStaff = $arrScheduleStaff;
		if($v_day =='Mon'){
			$v_day ='THU_2';
			$v_day_staff = $arrScheduleStaff[0]['C_MON'];
		}
		if($v_day =='Tue'){
			$v_day ='THU_3';
			$v_day_staff = $arrScheduleStaff[0]['C_TUE'];
		}	
		if($v_day =='Wed'){
			$v_day ='THU_4';
			$v_day_staff = $arrScheduleStaff[0]['C_WED'];
		}
		if($v_day =='Thu'){
			$v_day ='THU_5';
			$v_day_staff = $arrScheduleStaff[0]['C_THU'];
		}
		if($v_day =='Fri'){
			$v_day ='THU_6';
			$v_day_staff = $arrScheduleStaff[0]['C_FRI'];
		}
		if($v_day =='Sat'){
			$v_day ='THU_7';
			$v_day_staff = $arrScheduleStaff[0]['C_SAT'];
		}
		if($v_day =='Sun'){
			$v_day ='THU_8';
			$v_day_staff = $arrScheduleStaff[0]['C_SUN'];	
		}	
		
		$this->view->v_day_staff = $v_day_staff;		
		$arrScheduleToday = $objWebMenu->ScheduleUnitGetToday($v_week,$v_year,$v_day,1,$sOwner_name);
		$this->view->arrScheduleToday = $arrScheduleToday;
		//Lay nhac cong viec, trao doi cong viec
		$sStaffRole = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff_keep'],$_SESSION['staff_id'],'position_group_code');  
		$sUnitID = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff_keep'],$_SESSION['staff_id'],'unit_id');
		if($_SESSION['OWNER_ID']==Efy_Init_Config::_setParentOwnerId()){
			$sUnitType = 'PHONG_BAN';
		}else{
			$sUnitType = 'PHUONG_XA';
		}
		$arrTaskNoty = $objWebMenu->TaskWorkNotyGetAll($_SESSION['staff_id'],$sStaffRole,$sUnitID,$sUnitType);
		$this->view->arrTaskNoty = $arrTaskNoty;
		//Lay nhac van ban
		$objSession = new Efy_Init_Session();
		$arrPermission = $objSession->SesGetAllPermissionForSession($_SESSION['staff_id']);
		$sPermissionList = '';
		foreach ($arrPermission as $key=>$value){			
			$sPermissionList = $sPermissionList.$key.',';
		}
		$sRoleLeader = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'position_code');
		$iPosition= $objDocFun->docTestUser($_SESSION['staff_id']);
		$ojbEfyInitConfig = new Efy_Init_Config();
		$arrPositionConst =	$ojbEfyInitConfig->_setLeaderPostionGroup();
		//Lay nhom nguoi hien tai
		$arrGroup = $objWebMenu->getPropertiesDocumentByOwner('DM_NHOM_NGUOI_SD',$_SESSION['OWNER_CODE']);
		$psGroupIdList = Efy_Function_DocFunctions::docGetAllGroupReceived($arrGroup,$_SESSION['staff_id']);	
		if($_SESSION['staff_id']!='ADF82C07-AF2D-4EEE-8548-C7383CEAD213'){
			$arrReminder = $objWebMenu->docReminderGetAll($_SESSION['staff_id'],$sUnitID,$_SESSION['OWNER_ID'],$sPermissionList,$psGroupIdList,$iPosition);
		}
		$iDocNoti = 0;
		for($index = 0;$index < sizeof($arrReminder);$index++){
			if($arrReminder[$index]['C_COUNT'] > 0){
				$iDocNoti = 1;
				break;
			}
		}
		$this->view->iDocNoti = $iDocNoti;
		//Lay tin noi bat
		$arrHightlight = $objWebMenu->WebHightlightGetAll();
		$this->view->arrHightlight = $arrHightlight;
		//Lay van ban chi dao dieu hanh
		$iNumberDocOnWeb = '8';
                    // phan trang
                    $iCurrentPage = $this->_request->getParam('hdn_current_page','');		
		if ($iCurrentPage <= 1){
			$iCurrentPage = 1;
		}
                    $iNumRowOnPage = 8;
		$iNumRowOnPage = $objFilter->filter($arrInput['hdn_record_number_page']);
                    if($iCurrentPage == 0 || $iCurrentPage =="" ||$iCurrentPage == null){
			$iCurrentPage =1;
		}
		if($iNumRowOnPage == 0 || $iNumRowOnPage =="" ||$iNumRowOnPage == null){
			$iNumRowOnPage =8;
		}
                    $sFullTextSearch = $this->_request->getParam('FullTextSearch','');
		$this->view->currentPage = $iCurrentPage; //Gan gia tri vao View
		$this->view->numRowOnPage = $iNumRowOnPage; //Gan gia tri vao View
                    $this->view->FullTextSearch = $sFullTextSearch; 
		$arrDoc = $objWebMenu->WebDocViewOnWebGetAll(Efy_Init_Config::_setParentOwnerId(),$iNumberDocOnWeb, trim($sFullTextSearch),$iCurrentPage, $iNumRowOnPage);
		$this->view->arrDoc = $arrDoc;
                    $iNumberRecord = $arrDoc[0]['C_TOTAL_RECORD'];
                    $sdocpertotal ="Danh sách này không có văn bản nào";
		//Phan trang
		if (count($arrDoc) > 0){
			$this->view->sdocpertotal = "Danh sách có ".sizeof($arrDoc).'/'.$iNumberRecord." văn bản";
			//Sinh xau HTML mo ta so trang (Trang 1; Trang 2;...)
			$this->view->generateStringNumberPage = Efy_Publib_Library::_generateStringNumberPage($iNumberRecord, $iCurrentPage, $iNumRowOnPage,$sUrl) ;			
		}                  
		//var_dump($arrDoc);
		//Lay chuyen muc hien tren trang chu		
		$arrMenu = $this->view->arrMenu;			
		$MenuIdList = '';
		$i = 0;
		for($index = 0;$index < sizeof($arrMenu);$index++){
			if($arrMenu[$index]['C_WEB_DISPLAY']== '1'){
				$MenuIdList.= $arrMenu[$index]['PK_WEB_MENU'].',';
				$arrMenuHome[$i]['PK_WEB_MENU'] = $arrMenu[$index]['PK_WEB_MENU'];
				$arrMenuHome[$i]['C_NAME'] = $arrMenu[$index]['C_NAME'];
				$arrMenuHome[$i]['FK_WEB_MENU'] = $arrMenu[$index]['FK_WEB_MENU'];
				$arrMenuHome[$i]['FK_WEB_ARTICLE'] = $arrMenu[$index]['FK_WEB_ARTICLE'];	
				$arrMenuHome[$i]['C_WINDOWS_OPEN'] = $arrMenu[$index]['C_WINDOWS_OPEN'];		
				$arrMenuHome[$i]['C_VISIT_TOP'] = 'li'.$arrMenu[$index]['C_ORDER_LEVER1'];
				$arrMenuHome[$i]['C_VISIT_LEFT'] = 'mn_'.$arrMenu[$index]['C_ORDER_LEVER1'].'_'.$arrMenu[$index]['C_ORDER_LEVER2'].'_'.$arrMenu[$index]['C_ORDER_LEVER3'];
				$i = $i + 1;
			}
		}
		$MenuIdList = substr($MenuIdList,0,-1);
		$itr = ((int)($i/2) + ($i%2));
		//echo $this->view->CountInMenu;
		$arrResul = $objWebMenu->WebHomeInfoGetAll($MenuIdList,$this->view->CountInMenu);
		$this->view->arrResul = $arrResul;
		$this->view->arrMenuHome = $arrMenuHome;
		$this->view->countMenu = $itr;
	}
	/**
	 * 
	 * Enter description here ...
	 */
	public function getarticleAction(){	
		//Lay URL 
		$sUrl = $_SERVER['REQUEST_URI'];
		$this->view->sUrl = $sUrl;		
		// Tao doi tuong Zend_Filter
		$objFilter = new Zend_Filter();
		$ojbEfyLib = new Efy_Library();
		$objDocFun = new Efy_Function_DocFunctions();
		$objWebMenu = new web_modWebMenu();
		//Lay tin bai lien quan
		$ArticleID = $this->_request->getParam('articleid','');
		if($ArticleID != ''){
			$sleftmenu = $this->_request->getParam('sleftmenu','');
			$this->_redirect('web/home/viewarticle/?sleftmenu='.$sleftmenu.'&hdn_object_id='.$ArticleID);
		}else{
			//Lay so trang
			$iCurrentPage = $this->_request->getParam('hdn_current_page','');		
			if ($iCurrentPage <= 1){
				$iCurrentPage = 1;
			}
			//Lay so tin bai tren mot trang
			$icountArticle = Efy_Init_Config::_setCountInArticle();
			//Lay so tin bai tren mot menu lever1
			$icountArticleOfMenu = Efy_Init_Config::_setCountInMenuLever1();
			//Lay menu id
			$MenuId = $this->_request->getParam('menuid','');
			$this->view->MenuId = $MenuId;
			//$MenuName = $this->_request->getParam('menuname','');
			//$this->view->Menuname = Efy_Publib_Library::_convertETXToUnicode($MenuName);	
			$arrResul = $objWebMenu->WebArticleByMenuGetAll($MenuId,'',$iCurrentPage,$icountArticle,$icountArticleOfMenu);
			$this->view->arrResul = $arrResul;
			//Phan trang
			$iNumberRecord = $arrResul[0]['C_TOTAL_RECORD'];
			if (count($arrResul) > 0){
				//Sinh xau HTML mo ta so trang (Trang 1; Trang 2;...)
				$this->view->generateStringNumberPage = Efy_Publib_Library::_generateStringNumberPage($iNumberRecord, $iCurrentPage, $icountArticle,$sUrl) ;
			}
			//var_dump($arrResul);	
		}
	}
	/**
	 * 
	 * Enter description here ...
	 */
	public function searchAction(){	
		//Lay URL 
		$sUrl = $_SERVER['REQUEST_URI'];
		$this->view->sUrl = $sUrl;		
		// Tao doi tuong Zend_Filter
		$objFilter = new Zend_Filter();
		$ojbEfyLib = new Efy_Library();
		$objDocFun = new Efy_Function_DocFunctions();
		$objWebMenu = new web_modWebMenu();
		//Lay so trang
		$iCurrentPage = $this->_request->getParam('hdn_current_page','');		
		if ($iCurrentPage <= 1){
			$iCurrentPage = 1;
		}
		//Lay so tin bai tren mot trang
		$icountArticle = Efy_Init_Config::_setCountInArticle();
		//Lay menu id
		$sSearch = $this->_request->getParam('FullTextSearch','');
		$this->view->sSearch = $sSearch;	
		$arrResul = $objWebMenu->WebArticleBySearchGetAll($sSearch,$iCurrentPage,$icountArticle);
		//var_dump($arrResul);
		$this->view->arrResul = $arrResul;
		//Phan trang
		$iNumberRecord = $arrResul[0]['C_TOTAL_RECORD'];
		if (count($arrResul) > 0){
			//Sinh xau HTML mo ta so trang (Trang 1; Trang 2;...)
			$this->view->generateStringNumberPage = Efy_Publib_Library::_generateStringNumberPage($iNumberRecord, $iCurrentPage, $icountArticle,$sUrl) ;
		}
	}
	/*
	 * 
	 */
	public function viewarticleAction(){	
		//Lay URL 
		$sUrl = $_SERVER['REQUEST_URI'];
		$this->view->sUrl = $sUrl;		
		// Tao doi tuong Zend_Filter
		$objFilter = new Zend_Filter();
		$ojbEfyLib = new Efy_Library();
		$objDocFun = new Efy_Function_DocFunctions();
		$objWebMenu = new web_modWebMenu();
		//Lay article id
		$ArticleId = $this->_request->getParam('hdn_object_id','');
		$this->view->ArticleId = $ArticleId;
		//echo 'okkk'.$ArticleId;
		$arrResul = $objWebMenu->WebArticleGetSingle($ArticleId);
		$this->view->arrResul = $arrResul;
		//var_dump($arrResul);
	}
	/***
	 * 
	 */
	public function phoneAction(){	
	}
	/**
	 * 
	 * Enter description here ...
	 */
	public function viewdocAction(){	
		$this->view->bodyTitle = 'VĂN BẢN CHỈ ĐẠO ĐIỀU HÀNH';
		$ojbEfyLib = new Efy_Library();
		$objWebMenu = new web_modWebMenu();
		$objDocFun = new Efy_Function_DocFunctions();
		$objFunction =	new	Efy_Function_DocFunctions()	;
		$ojbEfyInitConfig = new Efy_Init_Config();
		//Lay cac gia tri const
		$this->view->arrConst =	$ojbEfyInitConfig->_setProjectPublicConst();
		//Lay Id doi tuong 
		$sentID = $this->_request->getParam('hdn_object_id','');	
		$this->view->sentID = $sentID;
		//echo $sentID;
		//Lay thong tin VB di va gui ra View
		$arrSent = $objWebMenu->docSentGetSingle($sentID);
		//var_dump($arrSent);exit;
		$this->view->arrSent = $arrSent;
	}	
	/**
	 * 
	 * Enter description here ...
	 */
	public function medialibAction(){	
		//Lay URL 
		$sUrl = $_SERVER['REQUEST_URI'];
		$this->view->sUrl = $sUrl;		
		$this->view->bodyTitle = 'THƯ VIỆN VIDEO';
		$objWebMenu = new web_modWebMenu();
		$iCurrentPage = $this->_request->getParam('hdn_current_page','');	
		if ($iCurrentPage <= 1){
			$iCurrentPage = 1;
		}	
		$sFullTextSearch = $this->_request->getParam('FullTextSearch','');
		$arrMedia = $objWebMenu->getListMediaByOwner("DM_VIDEO",$sFullTextSearch,$iCurrentPage,"10",$_SESSION['OWNER_CODE']);
		$iNumberRecord = $arrMedia[0]['TOTAL_RECORD'];
		$sdocpertotal ="Danh sách này không có video nào";		
		//Phan trang
		if (count($arrMedia) > 0){
			//Sinh xau HTML mo ta so trang (Trang 1; Trang 2;...)
			$this->view->generateStringNumberPage = Efy_Publib_Library::_generateStringNumberPage($iNumberRecord, $iCurrentPage, 10,$sUrl) ;
		}
		//exit;
		$this->view->arrMedia = $arrMedia;
		$this->view->FullTextSearch = $sFullTextSearch;
		$this->view->currentPage = $iCurrentPage;
	}	
	/**
	 * 
	 * Enter description here ...
	 */	
	public function trafficAction(){	
		//Lay URL 
		$sUrl = $_SERVER['REQUEST_URI'];
		$this->view->sUrl = $sUrl;			
		// Tieu de man hinh danh sach
		$this->view->bodyTitle = "KẾT QUẢ XỬ LÝ VI PHẠM CỦA CÁC ĐƠN VỊ";
		// Tao doi tuong Zend_Filter
		$objFilter = new Zend_Filter();
		$ojbEfyLib = new Efy_Library();
		$objDocFun = new Efy_Function_DocFunctions();
		// Lay toan bo tham so truyen tu form			
		$arrInput = $this->_request->getParams();		
		$objReceive = new web_modWebMenu();
		//Danh sach don vi
		$arrUnitProcess = $objReceive->getPropertiesDocumentByOwner('DM_DON_VI',$_SESSION['OWNER_CODE']);
		$this->view->arrUnitProcess = $arrUnitProcess;
		$dReceivedDate = date("d/m/Y");
		$this->view->ReceivedDate = $dReceivedDate;
		$iCurrentPage = $this->_request->getParam('hdn_current_page','');		
		if ($iCurrentPage <= 1){
			$iCurrentPage = 1;
		}
		//Lay thong tin quy dinh so row / page
		$iNumRowOnPage = 15;
		$iNumRowOnPage = $objFilter->filter($arrInput['hdn_record_number_page']);		
		if ($iNumRowOnPage <= $this->view->NumberRowOnPage){
			$iNumRowOnPage = $this->view->NumberRowOnPage;
		}		
		//Tieu chi tim kiem
		$sFullTextSearch = $this->_request->getParam('FullTextSearch','');
		$dFromDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('fromDate',''));
		$dToDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('toDate',''));
		$sOwnerCode = $this->_request->getParam('C_OWNER','');
		//Lay gia tri trong session
		if (isset($_SESSION['seArrParameter'])){
			$arrParaInSession = $_SESSION['seArrParameter'];
			//Tieu chi tim kiem
			$sOwnerCode = $arrParaInSession['sOwnerCode'];
			$sFullTextSearch = $arrParaInSession['FullTextSearch'];
			$dFromDate = $arrParaInSession['fromDate'];
			$dToDate = $arrParaInSession['toDate'];
			//Trang hien thoi
			$iCurrentPage = $arrParaInSession['hdn_current_page'];
			//So record/page
			$iNumRowOnPage = $arrParaInSession['hdn_record_number_page'];
			//Xoa gia tri trong session
			unset($_SESSION['seArrParameter']);								
		}
		if($iCurrentPage == 0 || $iCurrentPage =="" ||$iCurrentPage == null){
			$iCurrentPage =1;
		}
		if($iNumRowOnPage == 0 || $iNumRowOnPage =="" ||$iNumRowOnPage == null){
			$iNumRowOnPage =15;
		}
		$this->view->currentPage = $iCurrentPage; //Gan gia tri vao View
		$this->view->numRowOnPage = $iNumRowOnPage; //Gan gia tri vao View
		$sUnitId = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'unit_id');
		if($sOwnerCode==''){
			$sOwnerCode = $sUnitId;
		}
		if($sOwnerCode == $sUnitId){
			$this->view->edit = 1;
		}else{
			$this->view->edit = 0;
		}
		$arrResul = $objReceive->TrafficViolationsGetAll($sOwnerCode, $dFromDate, $dToDate, trim($sFullTextSearch), $iCurrentPage, $iNumRowOnPage);
		$iNumberRecord = $arrResul[0]['C_TOTAL_RECORD'];
		$sdocpertotal ="Danh sách này không có văn bản nào";
		//Phan trang
		if (count($arrResul) > 0){
			$this->view->sdocpertotal = "Danh sách có ".sizeof($arrResul).'/'.$iNumberRecord." vụ việc";
			//Sinh xau HTML mo ta so trang (Trang 1; Trang 2;...)
			$this->view->generateStringNumberPage = Efy_Publib_Library::_generateStringNumberPage($iNumberRecord, $iCurrentPage, $iNumRowOnPage,$sUrl) ;
			//Sinh chuoi HTML mo ta tong so trang (Trang 1; Trang 2;...) va quy dinh so record/page
			$this->view->generateHtmlSelectBoxPage = Efy_Publib_Library::_generateChangeRecordNumberPage($iNumRowOnPage,$sUrl);
		}
		//var_dump($arrResul);
		$this->view->arrResul = $arrResul;
		//
		$this->view->NumberRowOnPage 	= $this->_ConstPublic['NumberRowOnPage'];	
		$this->view->iCountElement = count($this->view->arrAllRecord);
		
		//Luu cac gia tri tim kiem duoc nhap vao tu form 
        $this->view->fromDate = $ojbEfyLib->_yyyymmddToDDmmyyyy($dFromDate);
        $this->view->toDate =  $ojbEfyLib->_yyyymmddToDDmmyyyy($dToDate);
        $this->view->FullTextSearch = $sFullTextSearch;
        $this->view->sOwnerCode = $sOwnerCode;
	}	
	public function addtrafficAction(){
		$this->view->bodyTitle = 'CHI TIẾT XỬ LÝ';
		$arrInput = $this->_request->getParams();
		$objDocFun = new Efy_Function_DocFunctions();
		$objTraffic = new web_modWebMenu();
		$ojbXmlLib = new Efy_Publib_Xml();
		$ojbEfyLib = new Efy_Library();
		$objFilter = new Zend_Filter();
		$ojbEfyInitConfig = new Efy_Init_Config();	
		//Lay danh sach don vi xu ly vi pham
		$arrUnitProcess = $objTraffic->getPropertiesDocumentByOwner('DM_DON_VI_XU_LY_VI_PHAM_ATGT',$_SESSION['OWNER_CODE']);
		$this->view->arrUnit=$arrUnitProcess;
		//Lay thong tin trang hien thoi
		$iCurrentPage = $this->_request->getParam('hdn_current_page',0);
		$this->view->currentPage	= $iCurrentPage;	
		//Lay thong tin quy dinh so row / page
		$iNumRowOnPage = $this->_request->getParam('hdn_record_number_page',0);
		$this->view->numRowOnPage	= $iNumRowOnPage;	
		//Tieu chi tim kiem
		$sFullTextSearch = $this->_request->getParam('FullTextSearch','');
		$dFromDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('fromDate',''));
		$dToDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('toDate',''));
		$sOwnerCode = $this->_request->getParam('C_OWNER','');
		//Luu cac gia tri tim kiem duoc nhap vao tu form 
        $this->view->fromDate = $ojbEfyLib->_yyyymmddToDDmmyyyy($dFromDate);
        $this->view->toDate =  $ojbEfyLib->_yyyymmddToDDmmyyyy($dToDate);
        $this->view->FullTextSearch = $sFullTextSearch;
        $this->view->sOwnerCode = $sOwnerCode;
		$this->view->AttachFile = $objDocFun->DocSentAttachFile(array(),0,10,true,42);
		if ($objFilter->filter($arrInput['C_OBJ_NAME']) != ""){		
			$arrFileNameUpload = $ojbEfyLib->_uploadFileList(10,$this->_request->getBaseUrl() . "/public/attach-file/",'FileName','!#~$|*');
			//lay nguoi tao
			$sStaffID = $_SESSION['staff_id'];
			$piUnitId = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'unit_id');			
			//Don vi xu ly
			$sUnitCode = $objFilter->filter($arrInput['C_UNIT_PROCESS']);
			$sUnitName = '';
			for($index = 0;$index < sizeof($arrUnitProcess);$index++){
				if($arrUnitProcess[$index]['C_CODE']==$sUnitCode){
					$sUnitName = $arrUnitProcess[$index]['C_NAME'];
					break;
				}
			}
			//Mang luu tham so update in database	
			$arrParameter = array(	
								'PK_TRAFFIC_VIOLATIONS'				=>'',										
								'FK_CREATE_STAFF_ID'				=>$sStaffID,
								'C_VIOLATIONS_DATE'					=>$ojbEfyLib->_ddmmyyyyToYYyymmdd($objFilter->filter($arrInput['C_PROCESS_DATE'])),
								'C_OBJECT_NAME'						=>$objFilter->filter($arrInput['C_OBJ_NAME']),
								'C_ADDRESS'							=>$objFilter->filter($arrInput['C_ADDRESS']),
								'C_CONTENT'							=>$objFilter->filter($arrInput['C_CONTEN']),
								'C_NUMBER_DECISION'					=>$objFilter->filter($arrInput['C_MUNBER']),
								'C_UNIT_PROCESS'					=>$sUnitCode,
								'C_UNIT_PROCESS_NAME'				=>$sUnitName,
								'C_FINES'							=>str_replace(',','',$objFilter->filter($arrInput['C_FINES'])),
								'ATTACH_FILE_NAME_LIST'				=>$arrFileNameUpload,			
								'C_OWNER_CODE'						=>$piUnitId
						);	
			$Result = "";
			//var_dump($arrParameter);exit;				
			$Result = $objTraffic->TrafficViolationsUpdate($arrParameter);				
			//Luu gia tri												
			$arrParaSet = array("sOwnerCode"=>$sOwnerCode,"hdn_current_page"=>$iCurrentPage,"hdn_record_number_page"=>$iNumRowOnPage,"FullTextSearch"=>$sFullTextSearch, "fromDate"=>$dFromDate, "toDate"=>$dToDate);
			$_SESSION['seArrParameter'] = $arrParaSet;
			$this->_request->setParams($arrParaSet);	
			$this->_redirect('web/home/traffic/');
		}
	}
	/**
	 * 
	 * Enter description here ...
	 */
	public function edittrafficAction(){
		$this->view->bodyTitle = 'CHI TIẾT XỬ LÝ';
		$arrInput = $this->_request->getParams();
		$objDocFun = new Efy_Function_DocFunctions();
		$objTraffic = new web_modWebMenu();
		$ojbXmlLib = new Efy_Publib_Xml();
		$ojbEfyLib = new Efy_Library();
		$objFilter = new Zend_Filter();
		$ojbEfyInitConfig = new Efy_Init_Config();	
		//Lay danh sach don vi xu ly vi pham
		$arrUnitProcess = $objTraffic->getPropertiesDocumentByOwner('DM_DON_VI_XU_LY_VI_PHAM_ATGT',$_SESSION['OWNER_CODE']);
		$this->view->arrUnit=$arrUnitProcess;
		//Lay thong tin trang hien thoi
		$iCurrentPage = $this->_request->getParam('hdn_current_page',0);
		$this->view->currentPage	= $iCurrentPage;	
		//Lay thong tin quy dinh so row / page
		$iNumRowOnPage = $this->_request->getParam('hdn_record_number_page',0);
		$this->view->numRowOnPage	= $iNumRowOnPage;	
		//Tieu chi tim kiem
		$sFullTextSearch = $this->_request->getParam('FullTextSearch','');
		$dFromDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('fromDate',''));
		$dToDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('toDate',''));
		$sOwnerCode = $this->_request->getParam('C_OWNER','');
		//Luu cac gia tri tim kiem duoc nhap vao tu form 
        $this->view->fromDate = $ojbEfyLib->_yyyymmddToDDmmyyyy($dFromDate);
        $this->view->toDate =  $ojbEfyLib->_yyyymmddToDDmmyyyy($dToDate);
        $this->view->FullTextSearch = $sFullTextSearch;
        $this->view->sOwnerCode = $sOwnerCode;
        //Lay thong tin chi tiet
		$sTraffic_violation_Id = $this->_request->getParam('hdn_object_id','');		
		$this->view->sTraffic_violation_Id = $sTraffic_violation_Id;        
       	$arrTrafficViolation= $objTraffic->TrafficViolationsGetSingle($sTraffic_violation_Id);
       	//var_dump($arrTrafficViolation);
		$this->view->arrTrafficViolation = $arrTrafficViolation;
       	$arFileAttach = $objTraffic->DOC_GetAllDocumentFileAttach($sTraffic_violation_Id,'TRAFFIC_VIOLATIONS','T_TRAFFIC_VIOLATIONS');	
		$this->view->AttachFile = $objDocFun->DocSentAttachFile($arFileAttach,sizeof($arFileAttach),10,true,42);
		if ($objFilter->filter($arrInput['C_OBJ_NAME']) != ""){		
			$arrFileNameUpload = $ojbEfyLib->_uploadFileList(10,$this->_request->getBaseUrl() . "/public/attach-file/",'FileName','!#~$|*');
			//lay nguoi tao
			$sStaffID = $_SESSION['staff_id'];
			$piUnitId = Efy_Publib_Library ::_getItemAttrById($_SESSION['arr_all_staff'],$_SESSION['staff_id'],'unit_id');	
			//Don vi xu ly
			$sUnitCode = $objFilter->filter($arrInput['C_UNIT_PROCESS']);
			$sUnitName = '';
			for($index = 0;$index < sizeof($arrUnitProcess);$index++){
				if($arrUnitProcess[$index]['C_CODE']==$sUnitCode){
					$sUnitName = $arrUnitProcess[$index]['C_NAME'];
					break;
				}
			}
			//Mang luu tham so update in database	
			$arrParameter = array(	
								'PK_TRAFFIC_VIOLATIONS'				=>$sTraffic_violation_Id,										
								'FK_CREATE_STAFF_ID'				=>$sStaffID,
								'C_VIOLATIONS_DATE'					=>$ojbEfyLib->_ddmmyyyyToYYyymmdd($objFilter->filter($arrInput['C_PROCESS_DATE'])),
								'C_OBJECT_NAME'						=>$objFilter->filter($arrInput['C_OBJ_NAME']),
								'C_ADDRESS'							=>$objFilter->filter($arrInput['C_ADDRESS']),
								'C_CONTENT'							=>$objFilter->filter($arrInput['C_CONTEN']),
								'C_NUMBER_DECISION'					=>$objFilter->filter($arrInput['C_MUNBER']),
								'C_UNIT_PROCESS'					=>$sUnitCode,
								'C_UNIT_PROCESS_NAME'				=>$sUnitName,
								'C_FINES'							=>str_replace(',','',$objFilter->filter($arrInput['C_FINES'])),
								'ATTACH_FILE_NAME_LIST'				=>$arrFileNameUpload,
								'C_OWNER_CODE'						=>$piUnitId						
						);	
			$Result = "";
			//var_dump($arrParameter);exit;				
			$Result = $objTraffic->TrafficViolationsUpdate($arrParameter);				
			//Luu gia tri												
			$arrParaSet = array("sOwnerCode"=>$sOwnerCode,"hdn_current_page"=>$iCurrentPage,"hdn_record_number_page"=>$iNumRowOnPage,"FullTextSearch"=>$sFullTextSearch, "fromDate"=>$dFromDate, "toDate"=>$dToDate);
			$_SESSION['seArrParameter'] = $arrParaSet;
			$this->_request->setParams($arrParaSet);	
			$this->_redirect('web/home/traffic/');
		}
	}
	/**
	 * Idea : Phuong thuc xoa
	 *
	 */
	public function deletetrafficAction(){
		// Tao doi tuong cho lop xu ly du lieu lien quan modul	
		$objTraffic = new web_modWebMenu();
		$ojbEfyLib = new Efy_Library();
		// Thuc hien lay du lieu tu form 		
		if($this->_request->isPost()){	
			// Lay toan bo tham so truyen tu form			
			$arrInput = $this->_request->getParams();				
			//Lay thong tin trang hien thoi
			$iCurrentPage = $this->_request->getParam('hdn_current_page',0);
			$this->view->currentPage	= $iCurrentPage;	
			//Lay thong tin quy dinh so row / page
			$iNumRowOnPage = $this->_request->getParam('hdn_record_number_page',0);
			$this->view->numRowOnPage	= $iNumRowOnPage;	
			//Tieu chi tim kiem
			$sFullTextSearch = $this->_request->getParam('FullTextSearch','');
			$dFromDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('fromDate',''));
			$dToDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('toDate',''));	
			$sOwnerCode = $this->_request->getParam('C_OWNER','');			
			//Lay Id doi tuong VB can xoa
			$sTrafficIdList = $this->_request->getParam('hdn_object_id_list',"");	
			//echo $sTrafficIdList;exit;
			if ($sTrafficIdList != ""){
				$sRetError = $objTraffic->TrafficViolationsDelete($sTrafficIdList);
				// Neu co loi			
				if($sRetError != null || $sRetError != '' ){											
					echo "<script type='text/javascript'>";
					echo "alert('$sRetError');\n";				
					echo "</script>";
				}else {		
					//Luu gia tri												
					$arrParaSet = array("sOwnerCode"=>$sOwnerCode,"hdn_current_page"=>$iCurrentPage,"hdn_record_number_page"=>$iNumRowOnPage,"FullTextSearch"=>$sFullTextSearch, "fromDate"=>$dFromDate, "toDate"=>$dToDate);
					$_SESSION['seArrParameter'] = $arrParaSet;
					$this->_request->setParams($arrParaSet);
					//Tro ve trang index												
					$this->_redirect('web/home/traffic/');
				}
			}
		}	
	
	}
	/**
	 * 
	 * Enter description here ...
	 */	
	public function printtrafficAction(){
		//Nhan bien truyen vao tu form
		$ojbEfyLib = new Efy_Library();
		$dFromDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('hdn_fromdate',""));	
		$dToDate = $ojbEfyLib->_ddmmyyyyToYYyymmdd($this->_request->getParam('hdn_todate',""));	
		$sFullTextSearch = $this->_request->getParam('hdn_FullTextSearch','');
		$sOwnerCode = $this->_request->getParam('hdn_owner_code','');		
		$objTraffic = new web_modWebMenu();
		$arrResul = $objTraffic->TrafficViolationsPrintGetAll($sOwnerCode,$dFromDate, $dToDate,$sFullTextSearch);
		if(sizeof($arrResul)>0){
			//Lay file template
			$path = $_SERVER['SCRIPT_FILENAME'];
			$path = substr($path, 0, -9);	
			$sTemplateUrl = str_replace("/", "\\", $path) . "templates\\other\\" . "temp_ketquaxlvp.htm";
			$v_html_header = $ojbEfyLib->_read_file($sTemplateUrl);
			$v_resul = str_replace("#FROM_DATE#",$this->_request->getParam('hdn_fromdate',""),$v_html_header);
			$v_resul = str_replace("#TO_DATE#",$this->_request->getParam('hdn_todate',""),$v_resul);
			$v_tr_group = '';
			$idem = 1;
			for($index = 0;$index < sizeof($arrResul);$index++){
				if($v_tr_group != $arrResul[$index]['C_UNIT_PROCESS']){
					$v_tr_group = $arrResul[$index]['C_UNIT_PROCESS'];
					$idem = 1;
					$v_conten = $v_conten.'<tr><td colspan="7" style="padding-left:3px;padding-right:3px;"><b><i>'.$arrResul[$index]['C_UNIT_PROCESS_NAME'].'</i></b></td></tr>';
					$v_conten = $v_conten.'<tr><td align="center" style="padding-left:3px;padding-right:3px;">'.$idem.'</td><td align="center" style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_VIOLATIONS_DATE'].'</td><td style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_OBJECT_NAME'].'</td><td style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_ADDRESS'].'</td><td style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_CONTEN'].'</td><td align="center" style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_NUMBER_DECISION'].'</td><td align="right"  style="padding-left:3px;padding-right:3px;">'.number_format($arrResul[$index]['C_FINES'],0,'.',',').'</td></tr>';
				}else{
					$idem = $idem + 1;
					$v_conten = $v_conten.'<tr><td align="center"  style="padding-left:3px;padding-right:3px;">'.$idem.'</td><td align="center" style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_VIOLATIONS_DATE'].'</td><td style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_OBJECT_NAME'].'</td><td style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_ADDRESS'].'</td><td style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_CONTEN'].'</td><td align="center" style="padding-left:3px;padding-right:3px;">'.$arrResul[$index]['C_NUMBER_DECISION'].'</td><td align="right"  style="padding-left:3px;padding-right:3px;">'.number_format($arrResul[$index]['C_FINES'],0,'.',',').'</td></tr>';	
				}
			}
			$v_resul = str_replace("#CONTEN#",$v_conten,$v_resul);
			$report_file = 'report.doc';
			$my_report_file = str_replace("/", "\\", $path) . "public\\export\\" . $report_file;
			$ojbEfyLib->_write_file($my_report_file,$v_resul);		
			$my_report_file = 'http://'.$_SERVER['HTTP_HOST'].Efy_Init_Config::_setWebSitePath().'public/export/'.$report_file;
			$this->view->my_report_file = $my_report_file; 				
		}else{
			echo "Kh&#244;ng c&#243; d&#7919; li&#7879;u k&#7871;t xu&#7845;t!";
			exit;			
		}
	}		
}
?>